import React, { Component, createRef } from "react";

class App extends Component {
  state = {};
  box = createRef();
  ipt = createRef();
  render() {
    return (
      <>
        <h2>用ref来获取dom节点</h2>
        <div className="box" ref={this.box}>
          box
        </div>
        <input type="text" ref={this.ipt} />
      </>
    );
  }
  componentDidMount() {
    console.log(this.box.current);
    this.ipt.current.focus();
  }
}

export default App;
